package com.mask.roll.edu.controller;


import com.mask.roll.common.code.ServiceEnums;
import com.mask.roll.common.constant.RollConstants;
import com.mask.roll.common.util.RollResponse;
import com.mask.roll.edu.entity.VO.subject.OneSubjectVO;
import com.mask.roll.edu.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author hx
 * @since 2021-10-23
 */
@RestController
@RequestMapping("/edu/subject")
@Api(tags = "课程分类管理")
public class SubjectController {
    @Resource
    private SubjectService subjectService;

    /**
     * 添加课程分类
     * @param file
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("excel添加分类")
    public RollResponse addSubject(MultipartFile file){
        subjectService.saveSubject(file,subjectService);
        return RollResponse.result(ServiceEnums.EXCEL_ADD_SUBJECT.getCode(),
                RollConstants.SUCCESS,ServiceEnums.EXCEL_ADD_SUBJECT.getMessage());
    }

    /**
     * 获取课程树形列表
     * @return
     */
    @GetMapping("/get/list")
    @ApiOperation("获取课程树形列表")
    public RollResponse getList(){
        List<OneSubjectVO> tree = subjectService.getTreeList();
        return RollResponse.result(ServiceEnums.SUBJECT_TREE_LIST.getCode(),
                RollConstants.SUCCESS,ServiceEnums.SUBJECT_TREE_LIST.getMessage(),tree);
    }
}

